package davidlauzon.activerecord.nodes;

import davidlauzon.activerecord.connection.ConnectionAdapter;
import davidlauzon.activerecord.visitor.SqlSerializer;


public abstract class Database extends Node
{
    /*********************************************************************************************
     * VARIABLES
     *********************************************************************************************/
    private String  _name;
    private Table[] _tables;
    private ConnectionAdapter _adapter;
    

    /*********************************************************************************************
     * ONE-LINER METHODS
     *********************************************************************************************/
    public String  getName()   { return _name; }
    public Table[] getTables() { return _tables; }
    
    public ConnectionAdapter getConnection()    { return _adapter; }
    public SqlSerializer     getSqlSerializer() { return _adapter.getSerializer(); }
    
    protected void setName(  String  name )  { _name = name; }
    
    public void setConnection(ConnectionAdapter adapter) { _adapter = adapter; }

    protected void setSqlSerializer(SqlSerializer serializer) { _adapter.setSerializer(serializer); }
    
    
    
    
    
    /*********************************************************************************************
     * PUBLIC METHODS
     *********************************************************************************************/
    @Override
    public String accept(SqlSerializer visitor) {
        return visitor.visit(this);
    }
    
    public void setTables(Table[] tables) {
        _tables = tables;
        for (int i = 0 ; i < _tables.length ; i++)
            _tables[i].setDatabase( this );
    }

}
